package com.llkj.safeearth;

import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

/**
 * 引导页
 */
public class SplashActivity extends BaseActivity {


    @Override
    protected int getLayoutId() {
        return R.layout.activity_splash;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        initAnim();
    }
    private void  initAnim() {
        View view = findViewById(R.id.main);
        ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(view, "alpha", 0.5f, 1.0f);
        objectAnimator.setDuration(2000);
        objectAnimator.addListener(new Animator.AnimatorListener(){

            @Override
            public void onAnimationStart(Animator animator) {

            }

            @Override
            public void onAnimationEnd(Animator animator) {
                doFinish();
            }

            @Override
            public void onAnimationCancel(Animator animator) {

            }

            @Override
            public void onAnimationRepeat(Animator animator) {

            }
        });
        objectAnimator.start();
    };

    private void doFinish() {
        int state = SPManager.get(SPManager.CACHE_DATA_FILE_NAME).getInt(SPManager.IS_FIRST_OPEN_APP,0);
        if(state == 1){
            Intent intent = new Intent(this,MainActivity.class);
            startActivity(intent);
        }else{
            Intent intent = new Intent(this,GuideActivity.class);
            startActivity(intent);
        }
        finish();
    }
}
